package com.recsmile.rpc.provider;

import com.recsmile.rpc.bo.RpcMessageRequest;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.util.UUID;

/**
 * Created by Administrator on 2016/8/3.
 */
public class MessageSendProxy implements InvocationHandler{
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        RpcMessageRequest rpcMessageRequest = new RpcMessageRequest();
        rpcMessageRequest.setMessageId(UUID.randomUUID().toString());
        rpcMessageRequest.setClassName(method.getDeclaringClass().getName());
        rpcMessageRequest.setMethodName(method.getName());
        rpcMessageRequest.setPerameterTypes(method.getParameterTypes());
        rpcMessageRequest.setArgs(args);

       MessageCallBack callBack =  RpcServerLoader.instance().getMessageSendHandler().sendRequest(rpcMessageRequest);
        return callBack.getResult();
    }
}
